#include "widget.h"
#include <QSplitter>
#include <QFileSystemModel>
#include <QTreeView>
#include <QListView>
#include <QDebug>
#include <QListWidget>
#include <QListWidgetItem>
#include <QIcon>
#include <QPushButton>
#include <QApplication>




Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(600, 400);


    QPushButton *p = new QPushButton(this);
    p->setGeometry(0, 350, 40, 40);
    connect(p, SIGNAL(clicked()), this, SLOT(onbbb()));
#if 0
    QSplitter *sp = new QSplitter(this);
    sp->resize(800,600);

    QFileSystemModel *md = new QFileSystemModel;
    md->setRootPath(QDir::currentPath());

    QTreeView *t = new QTreeView(sp);
    t->setModel(md);
    t->setRootIndex(md->index(QDir::currentPath()));

    QListView *l = new QListView(sp);
    l->setModel(md);
    l->setRootIndex(md->index(QDir::currentPath()));
    sp->show();
    {
        QFileSystemModel *model = new QFileSystemModel;
        QModelIndex parentIndex = model->index(QDir::currentPath());
        int numRows = model->rowCount(parentIndex);
        for (int row = 0; row < numRows; ++row) {
            QModelIndex index = model->index(row, 0, parentIndex);
            QString text = model->data(index, Qt::DisplayRole).toString();
            qDebug() << text;
        }
    }
#endif
    w = 0;
}

void Widget::onbbb()
{
    if (w==0){
        w = new QWidget(this);
        w->resize(300, 300);
        w->move(100,100);
        w->setWindowFlags(Qt::Popup);
        QListWidget *listWidget = new QListWidget(w);
//        listWidget->setViewMode(QListWidget::IconMode );
          listWidget->setResizeMode(QListWidget::Adjust);
          listWidget->setMovement(QListWidget::Static);

        listWidget->resize(w->size());
        for(int i =0; i < 100 ; i ++){
          QListWidgetItem *item = new QListWidgetItem(listWidget);
          QStyle::StandardPixmap sp = (QStyle::StandardPixmap)(i % 57);

          item->setData(Qt::DecorationRole, qApp->style()->standardPixmap(sp).scaled(QSize(32,32), Qt::KeepAspectRatio, Qt::SmoothTransformation) );
          item->setData(Qt::DisplayRole,QObject::tr("Item %1").arg(i));
          item->setData(Qt::UserRole + 1, QObject::tr("This is description %1").arg(i));
          item->setToolTip(QObject::tr("tool tip %1").arg(i));
          }
        listWidget->setItemDelegate(new MyDelegate(listWidget));


#if 0
        QListWidgetItem *newItem = new QListWidgetItem;
             newItem->setText("1111");
             QIcon d("aac.png");

             newItem->setIcon(d);
             newItem->setSizeHint(QSize(200,50));
             listWidget->insertItem(0, newItem);
              newItem = new QListWidgetItem;
              QIcon f("xbox.png");
                  newItem->setText("2222");
                  newItem->setIcon(f);
                  listWidget->insertItem(0, newItem);
#endif
    }
    w->show();
}

Widget::~Widget()
{

}
